<?php

/**
 * Created by PhpStorm.
 * user: Evan
 * Date: 16/8/8
 * Time: 上午1:19
 */
class Base extends MY_Api_Controller
{
	
	public function detail()
	{
		$ds_id = (int)$this->input->get_post('ds_id');
		$uid   = $this->uid;
		
		$this->load->service('direct_seeding/service_direct_seeding_base');
		$data = $this->service_direct_seeding_base->detail($ds_id, $uid);
		
		$this->json_output($data['data'], $data['status']);
	}
	
	/**
	 * 我的直播列表页
	 */
	public function my_lists()
	{
		$page  = (int)$this->input->get_post('page');
		$limit = (int)$this->input->get_post('limit');
		
		$this->load->service('direct_seeding/service_direct_seeding_base');
		$data = $this->service_direct_seeding_base->my_lists($this->uid, $page, $limit);
		
		$this->json_output($data['data'], $data['status']);
	}
	
    /**
     * 直播列表页
     */
    public function index()
    {
        $cid          = (int)$this->input->get_post('cid');
        $uid          = $this->uid;
        $page         = (int)$this->input->get_post('page');
        $limit        = (int)$this->input->get_post('limit');


        $this->load->service('direct_seeding/service_direct_seeding_index');
        $data = $this->service_direct_seeding_index->index($cid, $page, $limit, $uid);


        $this->json_output($data['data'], $data['status']);
    }


    public function load_more()
    {

    }


    /**
     * 当前直播
     */
    public function now()
    {
    	$this->load->service('direct_seeding/service_direct_seeding_base');
    	$data = $this->service_direct_seeding_base->now($this->uid);
    
    	$this->json_output($data['data'], $data['status']);
    }
    
    /**
     * 我参与的直播
     */
    public function partake()
    {
        $uid   = $this->uid;
        $page  = (int)$this->input->get_post('page');
        $limit = (int)$this->input->get_post('limit');


        $this->load->service('direct_seeding/service_direct_seeding_index');
        $data = $this->service_direct_seeding_index->partake($uid, $page, $limit);


        $o_data = array();
        if (!empty($data['data']))
        {
            foreach ($data['data'] as &$v)
            {
                unset($v['aid']);
                unset($v['auction_uid']);
                unset($v['auction_uname']);
                unset($v['anchor_uid']);
                unset($v['anchor_uname']);
                unset($v['real_duration']);
                //unset($v['join_num']);
                unset($v['end_type']);
                //unset($v['cover']);
                $o_data[] = $v;
            }
        }


        $this->json_output($o_data, $data['status']);
    }


    /**
     * 我发起的直播
     */
    public function launch()
    {
        $uid   = $this->uid;
        $page  = (int)$this->input->get_post('page');
        $limit = (int)$this->input->get_post('limit');


        $this->load->service('direct_seeding/service_direct_seeding_index');
        $data = $this->service_direct_seeding_index->launch($uid, $page, $limit);


        $o_data = array();
        if (!empty($data['data']))
        {
            foreach ($data['data'] as &$v)
            {
                unset($v['aid']);
                unset($v['auction_uid']);
                unset($v['auction_uname']);
                unset($v['anchor_uid']);
                unset($v['anchor_uname']);
                unset($v['real_duration']);
                unset($v['join_num']);
                unset($v['end_type']);
                //unset($v['cover']);
                $o_data[] = $v;
            }
        }


        $this->json_output($o_data, $data['status']);
    }


    /**
     * 直播上传封面界面
     */
    public function pre_start()
    {
        $uid   = $this->uid;
        $ds_id = (int)$this->input->get_post('ds_id');


        $this->load->service('direct_seeding/service_direct_seeding_base');
        $data = $this->service_direct_seeding_base->pre_start($ds_id, $uid);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 开启直播
     */
    public function start()
    {
        $uid      = $this->uid;
        $ds_id    = (int)$this->input->get_post('ds_id');
        $cover    = (int)$this->input->get_post('cover');
        $room_num = trim($this->input->get_post('room_num'));


        $this->load->service('direct_seeding/service_direct_seeding_start');
        $data = $this->service_direct_seeding_start->index($ds_id, $uid, $cover, $room_num);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 加入直播
     */
    public function join()
    {
        $uid   = $this->uid;
        $ds_id = (int)$this->input->get_post('ds_id');


        $this->load->service('direct_seeding/service_direct_seeding_join');
        $data = $this->service_direct_seeding_join->index($uid, $ds_id);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 观看直播
     */
    public function watch()
    {
        $uid   = $this->uid;
        $ds_id = (int)$this->input->get_post('ds_id');
        $type  = (int)$this->input->get_post('type');
        $pay_password = trim($this->input->get_post('pay_password'));


        $this->load->service('direct_seeding/service_direct_seeding_watch');
        $data = $this->service_direct_seeding_watch->index($uid, $ds_id, $type, $pay_password);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 关闭直播
     */
    public function close()
    {
        $uid   = $this->uid;
        $ds_id = (int)$this->input->get_post('ds_id');
        $is_abnormal = (int)$this->input->get_post('is_abnormal');


        $this->load->service('direct_seeding/service_direct_seeding_close');
        $data = $this->service_direct_seeding_close->index($uid, $ds_id, $is_abnormal);


        $this->json_output($data['data'], $data['status']);
    }
    
    /**
     * 退款并关闭直播
     */
    public function refund()
    {
    	$uid   = $this->uid;
    	$ds_id = (int)$this->input->get_post('ds_id');
    
    
    	$this->load->service('direct_seeding/service_direct_seeding_refund');
    	$data = $this->service_direct_seeding_refund->index($uid, $ds_id);
    
    
    	$this->json_output($data['data'], $data['status']);
    }
}